{include file="public/header" /}
<body style="background-color: #f1f1f1;" class="add_per">
<form action="{:url('userfamily/add_userfamily')}" class="horizontal" method="post" role="form">
    <div class="cont">
        <div class="wrapper">
            <ul>
                <li>
                    <span>姓名<em>*</em></span>
                    <input type="text" name="name" placeholder="请输入您的姓名">
                </li>
                <li class="sex">
                    <span>性别<em>*</em></span>
                    <select name="sex" id="sex">
                        <option value="1">男</option>
                        <option value="2">女</option>
                    </select>
                </li>
                <li class="paper">
                    <span>证件类型<em>*</em></span>
                    <select name="document_type" id="document_type">
                        <option value="1">身份证</option>
                        <option value="2">港澳通行证</option>
                    </select>
                </li>
                <li class="paper">
                    <span>证件号<em>*</em></span>
                    <input type="text" name="document_num" id="idcard" placeholder="请输入您的证件号码">
                </li>
                <li class="time">
                    <span>出生日期<em>*</em></span>
                    <input type="text" name="birth" placeholder="选择您的 出生日期" id="input1" class="time_point" value="">
                </li>
            </ul>
            <div class="save_box">
                <a >
                    <input type="button" value="确定" class="save_btn ajax-post">
                </a>
            </div>
        </div>
    </div>
</form>
</body>
{include file="public/footer" /}

<script type="text/javascript" src="__STATIC__/index/js/jquer_shijian.js"></script>
<script type="text/javascript">
    //默认点击显示
    $(".time_point").shijian();
    $("#idcard").blur(function () {
        //选择的身份证才进行验证
       // alert($('#document_type option:selected').val());
        if ($('#document_type option:selected').val() == '1') {
            checkIdCard();
        }

    });
    function checkIdCard() {
        //获取输入身份证号码
        var ic = $("#idcard").val();
        ic = checkId(ic);

        var ic = String(ic);
        //获取性别
        var gender = ic.slice(14, 17) % 2 ? "1" : "2"; // 2代表男性，1代表女性
        set_select_checked(gender);
        var birthday = '';
        if (ic.length == 15) {
            birthday = "19" + idCard.substr(6, 6);
        } else if (ic.length == 18) {
            birthday = ic.substr(6, 8);
        }
        birthday = birthday.replace(/(.{4})(.{2})/, "$1-$2-");
        $("#input1").val(birthday);
    }
    function set_select_checked(checkValue) {
        var select = document.getElementById("sex");
        for (var i = 0; i < select.options.length; i++) {
            if (select.options[i].value == checkValue) {
                select.options[i].selected = true;
                break;
            }
        }
    }
    function checkId(pId) {
        //检查身份证号码
        var arrVerifyCode = [1, 0, "x", 9, 8, 7, 6, 5, 4, 3, 2];
        var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
        var Checker = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1];
        var Ai2 = '';
        var  Ai1 = '';
        if (pId.length == 0) {
            layer.msg("请先填写身份证号", {icon: 6})

        }
        if (pId.length != 15 && pId.length != 18) {
            layer.msg("身份证号共有15位或18位", {icon: 6})

        }
        var Ai = pId.length == 18 ? pId.substring(0, 17) : pId.slice(0, 6) + "19" + pId.slice(6, 16);
        if (!/^\d+$/.test(Ai))
            layer.msg("身份证除最后一位外，必须为数字！", {icon: 6})

        var yyyy = Ai.slice(6, 10), mm = Ai.slice(10, 12) - 1, dd = Ai.slice(12, 14);
        var d = new Date(yyyy, mm, dd), now = new Date();
        var year = d.getFullYear(), mon = d.getMonth(), day = d.getDate();
        if (year != yyyy || mon != mm || day != dd || d > now || year < 1800)
            layer.msg("身份证输入错误！", {icon: 6})
        for (var i = 0, ret = 0; i < 17; i++) ret += Ai.charAt(i) * Wi[i];
        var strVerifyCode = arrVerifyCode[ret %= 11];
        if(isRealNum(strVerifyCode)){
            Ai += arrVerifyCode[ret %= 11];
            Ai1 = Ai ;
            Ai2 = Ai ;
        }else{
            Ai1 =Ai + strVerifyCode.toUpperCase();
            Ai2 =Ai + strVerifyCode.toLowerCase();

        }

        if (pId.length == 18 &&( pId != Ai1&&Ai2!=pId)) {
            layer.msg("身份证输入错误！", {icon: 6})
        } else {

            return pId;
        }
    };
    //数字判断函数IsNumeric()
    function isRealNum(val){
        // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
        if(val === "" || val ==null){
            return false;
        }
        if(!isNaN(val)){
            return true;
        }else{
            return false;
        }
    }
</script>


<script>
    $(function () {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes();
        $(".sel_time .time_point").val(currentdate);
        console.log(currentdate);
        console.log(date);
    });
</script>
</html>